package com.hspedu.newData.dmsxl.哈希表;

import org.junit.Test;

import java.util.HashSet;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-22 
 * @Version: 1.0
 */

public class LC202快乐数 {

    public boolean isHappy(int n) {

        HashSet<Integer> set = new HashSet<>();
        while(!set.contains(n)){
            set.add(n);
            int sum = 0;
            while (n >= 1){
                int t = n % 10;
                sum += t*t;
                n = n / 10;
            }
            n = sum;
            if (n == 1){
                return true;
            }
        }
        return false;


    }


    @Test
    public void test() {
        // 测试代码

        boolean happy = isHappy(2);
        System.out.println("-------");
    }
}
